/*
 @file    selectComponent.h
 @author  Rossella Petrucci, Alvise Rigo, Alberto Rubin
*/

#ifndef SELECTCOMPONENT_H_
#define SELECTCOMPONENT_H_

#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/keypoints/sift_keypoint.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/search/kdtree.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/features/fpfh_omp.h>
#include <pcl/features/pfh.h>
#include <pcl/features/pfhrgb.h>
#include <pcl/features/3dsc.h>
#include <pcl/features/shot_omp.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/registration/transformation_estimation_svd.h>
#include <pcl/registration/icp.h>
#include <pcl/registration/correspondence_rejection_sample_consensus.h>
#include <pcl/common/transforms.h>
#include <pcl/surface/grid_projection.h>
#include <pcl/surface/gp3.h>
#include <pcl/surface/marching_cubes_greedy.h>
#include <pcl/surface/marching_cubes_greedy_dot.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/sample_consensus/sac_model_line.h>

#include <vector>
#include <stdlib.h>
#endif

/*! Finds the cluster that contains the clicked point.
 \param[in] input point cloud clicked.
 \param[out] output indices of the points that belong to the selected cluster.
 \param[in] selectedPointIndex index of the clicked point.
 \param[in] threshold the spatial cluster tolerance as a measure in the L2 Euclidean space.
*/
void segmentCluster(pcl::PointCloud<pcl::PointXYZRGB>::Ptr input, pcl::PointIndices::Ptr output, int selectedPointIndex, double threshold, bool ribbon = false );

/*! Colors the cluster that contains the clicked point.
 \param[in] input point cloud clicked.
 \param[in] indices indices of the points that belong to the selected cluster.
 \param[in] r red value of the desidered color.
 \param[in] g green value of the desidered color.
 \param[in] b blue value of the desidered color.
*/
void colorCluster(pcl::PointCloud<pcl::PointXYZRGB>::Ptr input, pcl::PointIndices::Ptr indices, double r, double g, double b);

/*! Returns the point cloud representative the selected component.
 \return point cloud representative the selected component.
*/
pcl::PointCloud<pcl::PointXYZRGB>::Ptr getSelectedComponent();

/*! Returns the point cloud representative the ribbon cable.
 \return point cloud representative the ribbon cable.
*/
pcl::PointCloud<pcl::PointXYZRGB>::Ptr getRibbonCable();

/*! Finds the corresponding cluster in the source registered point cloud.
 \param[in] target target point cloud clicked.
 \param[in] source source point cloud.
 \param[out] outIndices indices of the points that belong to the selected cluster.
 \param[in] selectedPointIndex index of the clicked point.
 \param[in] threshold the spatial cluster tolerance as a measure in the L2 Euclidean space.
 \return true if the cluster is found, false otherwise.
*/
bool findCluster(pcl::PointCloud<pcl::PointXYZRGB>::Ptr target, pcl::PointCloud<pcl::PointXYZRGB>::Ptr source, pcl::PointIndices::Ptr outIndices, int selectedPointIndex, double threshold );

bool isRibbonCableCorrect(pcl::PointCloud<pcl::PointXYZRGB>::Ptr source);

#endif /* SELECTCOMPONENT_H_ */
